|
|
|
|
|
|
|
The list of services is necessary to allow the user to select which services to start or stop. Sure, you can hard-code those services needed for IIS 4.0 (the current version of Internet Information Server), but then you would have to recode the utility for future versions of IIS if Microsoft changes the name or selection of services it uses. |
|
|
|
|
|
|
|
|
You must be able to obtain the running state of a service, both to determine when the operation you have requested is complete and to obtain the initial service state in order to support a restore operation. |
|
|
|
|
|
|
|
|
Before looking at the actual API functions available to work with services, you need to know a little bit about how services are managed. |
|
|
|
|
|
|
|
|
There are two types of objects we are concerned with.1 The first object is called the Service Control Manager. The Service Control Manager is a part of the operating system that manages the services on a system and maintains the internal service database for the system. |
|
|
|
|
|
|
|
|
The other object is that of the service itself. You must use the Service Control Manager to obtain a handle to a service. |
|
|
|
|
|
|
|
|
Service Control Manager Functions |
|
|
|
|
|
|
|
|
The OpenSCManager function is used to open the Service Control Manager. It is defined in C as follows: |
|
|
|
|
|
|
|
|
SC_HANDLE OpenSCManager( LPCTSTR lpMachineName, // pointer to machine name string
LPCTSTR lpDatabaseName, // pointer to database name string
DWORD dwDesiredAccess // type of access
); |
|
|
|
|
|
|
|
|
The return value is a 32-bit Long that contains a handle to the Service Control Manager object. Note that it is possible to open the Service Control Manager on a remote system. The lpDatabaseName parameter is always set to NULL or the constant SERVICES_ACTIVE_DATABASE, both of which cause the function to use the current active database. It looks like the designers had the idea of supporting multiple service databases at some point, but that capability has not yet shown up. |
|
|
|
 |
|
 |
|
|
1 Note that the term "object" here means a Win32 object, not a COM/ActiveX object. As with other Win32 objects, you can expect to find an API function to create or open the object and then return an object handlea 32-bit Long value that identifies the object. You can also expect to find another API function to close the object when you are finished with it. |
|
|
|
|
|